import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

//Locale资源类
class DemoLocalizations1 {
  DemoLocalizations1(this.isZh);
  //是否为中文
  bool isZh = false;
  //为了使用方便，我们定义一个静态方法
  static DemoLocalizations1? of(BuildContext context) {
    return Localizations.of<DemoLocalizations1>(context, DemoLocalizations1);
  }

  //Locale相关值，title为应用标题
  String get title {
    return isZh ? "中文标题" : "English Title";
  }
  //... 其他的值
}

//Locale代理类
class DemoLocalizations1Delegate
    extends LocalizationsDelegate<DemoLocalizations1> {
  const DemoLocalizations1Delegate();

  //是否支持某个Local
  @override
  bool isSupported(Locale locale) => ['en', 'zh'].contains(locale.languageCode);

  // Flutter会调用此类加载相应的Locale资源类
  @override
  Future<DemoLocalizations1> load(Locale locale) {
    print("加载某区域的资源：$locale");
    return SynchronousFuture<DemoLocalizations1>(
        DemoLocalizations1(locale.languageCode == "zh"));
  }

  @override
  bool shouldReload(DemoLocalizations1Delegate old) => false;
}
